<!--
 * @Description: 环检照片上传
 * @Autor: 何兴家
 * @Date: 2021-02-22 13:18:24
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-02-24 14:15:53
-->
<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :labelWidth="0" :cols="6" :isSubmitBtn="false"></FormPanel>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';

export default {
  props: ['defaultData', 'formDisabled'],
  mixins: [dictionary],
  data() {
    return {
      formList: this.createFormList()
    };
  },
  watch: {
    formDisabled(newVal, oldVal) {
      // console.log(newVal, '图片上传禁用状态改变');
      this.formList.forEach(item => {
        item.type != 'BREAK_SPACE' && (item.disabled = newVal);
      });
    }
  },
  mounted() {},
  methods: {
    createFormList() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '外观'
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'LEFT_FRONT',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '左前'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'RIGHT_FRONT',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '右前'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'LEFT_REAR',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '左后'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'RIGHT_REAR',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '右后'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'LEFT_SIDE',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '左侧'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'RIGHT_SIDE',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '右侧'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'TOP',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '顶部'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'OTHER_REPLENISH1',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '其他补充1'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'OTHER_REPLENISH2',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '其他补充2'
          }
        },
        {
          type: 'BREAK_SPACE',
          label: '内饰'
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'TRIM1',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '内饰1'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'TRIM2',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '内饰2'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'TRIM3',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '内饰3'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'TRIM4',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '内饰4'
          }
        },
        {
          type: 'BREAK_SPACE',
          label: '底盘'
        },

        {
          type: 'UPLOAD_IMG',
          fieldName: 'UNDERPAN1',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '底盘1'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'UNDERPAN2',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '底盘2'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'UNDERPAN3',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '底盘3'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'UNDERPAN4',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '底盘4'
          }
        },
        {
          type: 'BREAK_SPACE',
          label: '受损'
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'DAMAGED1',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '受损1'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'DAMAGED2',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '受损2'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'DAMAGED3',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '受损3'
          }
        },
        {
          type: 'UPLOAD_IMG',
          fieldName: 'DAMAGED4',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '受损4'
          }
        }
      ];
    },
    // 初始化图片默认数据
    initDefaultData(defaultData) {
      // console.log(defaultData, '初始化图片');
      this.formList.forEach(item => {
        if (item.type != 'BREAK_SPACE') {
          item.initialValue = defaultData[item.fieldName] ? [defaultData[item.fieldName]] : [];
        }
      });
    },
    // 清空表单数据
    clearFormData() {
      this.$refs.formPanel.RESET_FORM();
    },
    // 获取页面图片数据
    async getFormData() {
      return this.$refs.formPanel.GET_FORM_DATA();
    }
  }
};
</script>

<style scoped></style>
